<template>
	<view class="content">
		<view class="uni-panel-bottom">
			<view class="uni-panel-item">
				<image class="uni-image" src="/static/img/back.png" mode="widthFix" @click="clickBack"></image>
				<view class="uni-panel-left">
					<text class="uni-text-item">你好，{{accountName}}同学，请点击视频课程开始学习</text>
				</view>
			</view>
			<view class="uni-panel">
				<view class="uni-panel-book" v-for="(item, index) in listBook" :key="index" @click="clickBtnItem(item)">
					<text class="uni-text-word" >{{item.name}}</text>
					<view class="uni-book-bottom">
						<image class="uni-word-image" :src="apiUrl+item.image" mode="widthFix" ></image>
						<!-- <image class="uni-image-video" src="/static/img/play.png" mode="heightFix"></image> -->
					</view>
				</view>
			</view>
		</view>
		
		<view class="uni-panel-video" v-if='isShowVideo'>
			<image class="uni-image-close" src="/static/img/back.png" mode="widthFix" @click="clickCloseVideo"></image>
			<video class="uni-video" :src="videoFile"
			 @error="videoErrorCallback" controls :poster="imageFile"></video>
			 
		</view>	 
			 
	</view>
</template>

<script>
	import { getVideoList } from '@/api/api.js';
	import store from "../../store";
	import { HTTP_REQUEST_URL } from '@/config/app.js';
	export default {
		mounted() {
		        // #ifdef APP-PLUS
		        plus.screen.lockOrientation('landscape');
		        // #endif
		    },
		data() {
			return {
				userId: 0,
				accountName: '',
				listBook: [],
				apiUrl: HTTP_REQUEST_URL,
				isShowVideo: false,
				videoFile: '',
				imageFile: '',
			}
		},
		onLoad(options) {
			const userInfo = store.state.app.userInfo;
			if( userInfo){
				this.accountName = userInfo.nickname;
				this.userId = userInfo.id;
			}
			let student = uni.getStorageSync('student_info');
			if( student){
				this.accountName = student.nickname;
				this.userId = student.id;
			}
				
			let that = this;
			let params = {pageSize:256, params:{user_id: this.userId}};
			getVideoList(params).then(res => {
				console.log(res)
				let ret = [];
				if( res.data ){
					for( let item of res.data.rows){
						ret.push(item);
					}
				}
				that.listBook = ret;
			})
		},
		methods: {
			clickBack(){
				uni.navigateBack();
			},
			clickBtnItem(item){
				this.videoFile = this.apiUrl+item.video_file;
				this.imageFile = this.apiUrl+item.image;
				this.isShowVideo = true;
			},
			videoErrorCallback: function(e) {
				uni.showToast({
					content: e.target.errMsg,
					showCancel: false
				})
			},
			clickCloseVideo(){
				this.isShowVideo = false;
			}
		}
	}
</script>

<style>
	page {
		height: 100%;
	}
	.content {
		width: 100%;
		height: 100%;
		background-image: url('../../static/img/bg.jpg');
		background-size: 100% 100%;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	
	.uni-panel-c {
		width: 90%;
		height: 100%;
		display: flex;
		flex-direction: column;
	}
	
	.uni-panel-top {
		width: 100%;
		height: 20%;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}
	.uni-image {
		width: 6%;
	}
	.uni-text-logo{
		color: black;
		font-size: 10vmin;
		margin-left: 2%;
		text-align: center;
		font-weight: bold;
		letter-spacing: 10rpx;
		font-family: "楷体";
	}
	
	.uni-panel-bottom-bk {
		position: absolute;
		left: 5%;
		top: 20%;
		width: 90%;
		height: 80%;
		background-color: white;
		opacity: 0.3;
		border-radius: 40rpx;
	}
	.uni-panel-bottom {
		width: 100%;
		height: 80%;
		display: flex;
		flex-direction: column;
		align-items: center;
		z-index: 1;
	}
	.uni-panel-item {
		margin-top: 2%;
		width: 90%;
		height: 15%;
		display: flex;
		flex-direction: row;
		align-items: center;
	}
	.uni-panel-left {
		display: flex;
		flex-direction: column;
		margin-left: 2%;
	}
	
	.uni-text-item{
		font-size: 5vmin;
		color: white;
		font-weight: bold;
		letter-spacing: 1rpx;
		text-shadow:
		    -1px -1px 0 #000,
		    1px -1px 0 #000,
		    -1px 1px 0 #000,
		    1px 1px 0 #000; /* 调整偏移量和颜色来设置描边宽度和颜色 */
	}
	
	.uni-panel {
		width:100%;
		height: 85%;
		display: flex;
		flex-direction: row;
		flex-wrap: wrap;
		overflow: auto;
	}
	
	.uni-panel-book {
		height: 35%;
		width: 20%;
		margin-left: 3%;
		margin-top: 20rpx;
		background-color: #c8ede5;
		display: flex;
		flex-direction: column;
		align-items: center;
		border-radius: 10rpx;
	}
	
	.uni-word-image {
		width: 35%;
		height: 70%;
	}
	
	.uni-image-video{
		position: absolute;
		height: 10%;
	}
	
	.uni-text-word{
		font-size: 3vmin;
		color: black;
		margin: 1% 0 0 2%;
	}
	
	.uni-book-bottom{
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
		width: 90%;
		height: 80%;
		margin-bottom: 1%;
		background-color: black;
	}
	
	.uni-book-bottom-right{
		display: flex;
		flex-direction: column;
		width: 60%;
		margin-left: 40rpx;
	}
	
	.progress-box{
		width: 95%;
	}
	
	.uni-panel-video{
		position: absolute;
		background-image: url('../../static/img/bg.jpg');
		background-size: 100% 100%;
		left: 0;
		top: 0;
		width:100%;
		height:100%;
		background-color: black;
		display: flex;
		flex-direction: column;
		z-index: 2;
	}
	.uni-image-close {
		width: 5%;
		margin-top: 4%;
	}
	.uni-video{
		width:100%;
		height:100%;
	}
</style>
